Imports System
Imports System.Configuration
Imports System.Web.Configuration

Partial Class Usercontrols_Admin_PollSettings
    Inherits UserControlBase

#Region " Enums, Memebers and Properties "



#End Region

#Region " Page Events "

    Protected Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init
        Me.MessageLabel = Me.uxMessagesLabel
    End Sub

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Me.Page.IsPostBack = False Then
            LoadSettings()
        End If

        Me.uxAdminPanel.Visible = ShowControls(SecurityMask.Admin, True)

    End Sub

#End Region

#Region " Save Data "

    Public Sub SaveSettings()
        Dim configuration As Configuration = WebConfigurationManager.OpenWebConfiguration("~")
        Dim AppSettingsSection As AppSettingsSection = CType(configuration.GetSection("appSettings"), AppSettingsSection)

        If Not (AppSettingsSection Is Nothing) Then

            If IsNothing(AppSettingsSection.Settings("DisplayMostViewedPolls")) Then
                AppSettingsSection.Settings.Add("DisplayMostViewedPolls", Me.uxDisplayMostViewedPollsCheckBox.Checked)
            Else
                AppSettingsSection.Settings("DisplayMostViewedPolls").Value() = Me.uxDisplayMostViewedPollsCheckBox.Checked
            End If

            If IsNothing(AppSettingsSection.Settings("DisplayMostCommentsPolls")) Then
                AppSettingsSection.Settings.Add("DisplayMostCommentsPolls", Me.uxDisplayMostCommentsPollsCheckbox.Checked)
            Else
                AppSettingsSection.Settings("DisplayMostCommentsPolls").Value() = Me.uxDisplayMostCommentsPollsCheckbox.Checked
            End If

            If IsNothing(AppSettingsSection.Settings("DisplayHighestRankedPolls")) Then
                AppSettingsSection.Settings.Add("DisplayHighestRankedPolls", Me.uxDisplayHighestRankedPollsCheckbox.Checked)
            Else
                AppSettingsSection.Settings("DisplayHighestRankedPolls").Value() = Me.uxDisplayHighestRankedPollsCheckbox.Checked
            End If

            If IsNothing(AppSettingsSection.Settings("EnableUserPolls")) Then
                AppSettingsSection.Settings.Add("EnableUserPolls", Me.uxEnableUserPollsCheckbox.Checked)
            Else
                AppSettingsSection.Settings("EnableUserPolls").Value() = Me.uxEnableUserPollsCheckbox.Checked
            End If

            configuration.Save()
        End If

    End Sub

    Public Sub SaveSettings(ByVal key As String, ByVal value As String)
        Dim configuration As Configuration = WebConfigurationManager.OpenWebConfiguration("~")
        Dim AppSettingsSection As AppSettingsSection = CType(configuration.GetSection("appSettings"), AppSettingsSection)

        If Not (AppSettingsSection Is Nothing) Then
            AppSettingsSection.Settings(key).Value = value
            MainConfiguration.Save()
        End If
    End Sub

#End Region

#Region " Load Data "

    Public Sub LoadSettings()

        If Not (AppSettingsSection Is Nothing) Then
            If IsNothing(AppSettingsSection.Settings("DisplayMostViewedPolls")) Then
                Me.uxDisplayMostViewedPollsCheckBox.Checked = True
            Else
                Me.uxDisplayMostViewedPollsCheckBox.Checked = AppSettingsSection.Settings("DisplayMostViewedPolls").Value()
            End If

            If IsNothing(AppSettingsSection.Settings("DisplayMostCommentsPolls")) Then
                Me.uxDisplayMostCommentsPollsCheckbox.Checked = True
            Else
                Me.uxDisplayMostCommentsPollsCheckbox.Checked = AppSettingsSection.Settings("DisplayMostCommentsPolls").Value()
            End If

            If IsNothing(AppSettingsSection.Settings("DisplayHighestRankedPolls")) Then
                Me.uxDisplayHighestRankedPollsCheckbox.Checked = True
            Else
                Me.uxDisplayHighestRankedPollsCheckbox.Checked = AppSettingsSection.Settings("DisplayHighestRankedPolls").Value()
            End If

            If IsNothing(AppSettingsSection.Settings("EnableUserPolls")) Then
                Me.uxEnableUserPollsCheckbox.Checked = False
            Else
                Me.uxEnableUserPollsCheckbox.Checked = AppSettingsSection.Settings("EnableUserPolls").Value()
            End If

        End If

    End Sub

#End Region

#Region " Form Controls Events "

#End Region

#Region " Helpers and Methods "



#End Region

End Class
